package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo9 {
    public static void main(String[] args) {
        //UserInfo userInfo = InputUtil.getInputObject(new UserInfo(), "欢迎注册");
        try (Connection connection = DBUtil.getConnection()) {
            Statement statement = connection.createStatement();
            connection.setAutoCommit(false);
            String sql ="insert into userinfo (username, password, nickname ,age) " +
                    "  value ('李四','123456','老四',22)";
            int i = statement.executeUpdate(sql);
            System.out.println(i>0?"插入成功":"插入失败");
            String sqlc="select username from userinfo";
            ResultSet resultSet = statement.executeQuery(sqlc);
            while(resultSet.next()){
                System.out.println(resultSet.getString(1));
            }

            connection.commit();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
